package com.kyxx.topics.activity;

import android.content.Intent;
import android.text.Editable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.kyxx.topics.BaseActivity;
import com.kyxx.topics.R;
import com.kyxx.topics.adapter.OnTextChangeAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EditMemberActivity2 extends BaseActivity {
    @Bind(R.id.tv_edit_member_cancle)
    TextView tvEditMemberCancle;
    @Bind(R.id.tv_edit_member_baocun)
    TextView tv_edit_member_baocun;
    @Bind(R.id.et_edit_member_content)
    EditText et_edit_member_content;
    private int num = -1;
    private String content;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_edit_member2);
        ButterKnife.bind(this);
        num = getIntent().getIntExtra("type",-1);
        content = getIntent().getStringExtra("content");
    }

    @Override
    protected void findViewById() {

    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void processLogic() {
        et_edit_member_content.setText(content);
        et_edit_member_content.setSelection(content.length());
        if(content.length()>0){
            tv_edit_member_baocun.setEnabled(true);
        }else {
            tv_edit_member_baocun.setEnabled(false);
        }
        et_edit_member_content.addTextChangedListener(new OnTextChangeAdapter(){
            @Override
            public void afterTextChanged(Editable s) {
                if(s.length()>0){
                    content = s.toString();
                    tv_edit_member_baocun.setEnabled(true);
                }else {
                    tv_edit_member_baocun.setEnabled(false);
                }
            }
        });
    }


    @OnClick({R.id.tv_edit_member_cancle, R.id.tv_edit_member_baocun})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_edit_member_cancle:
                finish();
                break;
            case R.id.tv_edit_member_baocun:
                //数据是使用Intent返回
                Intent intent = new Intent();
                //把返回数据存入Intent
                intent.putExtra("result", content);
                //设置返回数据
                this.setResult(num, intent);
                //关闭Activity
                finish();
                break;
        }
    }

}
